000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. PASSWORDGENERATOR.
       AUTHOR. GROEP 28.
       AUTHOR. MICHEL GRYP.
       AUTHOR. MICHAEL HEUGHEBAERT.
       AUTHOR. MATTHIAS REYNAERT.
       
       ENVIRONMENT DIVISION.
       
       DATA DIVISION.
      
       WORKING-STORAGE SECTION.
       01 PASSWORDVALUEOPTIONS.
         03 PASSWORDUPPERCASE   PIC X(26) 
                                VALUE "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
         03 PASSWORDLOWERCASE   PIC X(26) 
                                VALUE "abcdefghijklmnopqrstuvwxyz".
         03 PASSWORDNUMBERS     PIC X(10) 
                                VALUE "0123456789".  
      
       01 HELPVALUES.
         03 REQUIREDSIGNLOCATIONS.
           05 CAPITALLOC          PIC 9.
           05 NUMBER1LOC          PIC 9.
           05 NUMBER2LOC          PIC 9.
         03 RANDOMS.
           05 RANDOMPOINTER       PIC 9(2).
           05 RANDOMSIGNVALUE     PIC X.
         03 FILLPASSWORDHELPERS.
           05 COUNTER             PIC 9 VALUE 1.
           
       01 PAZZWORD.
        03 PASSWORDVALUE          PIC X OCCURS 8.
        03 PASSWORDSTRING REDEFINES PASSWORDVALUE PIC X(8).
       
       PROCEDURE DIVISION RETURNING PASSWORDSTRING. 
       PGM.
      * Paswoord moet bestaan uit minimum 1 hoofdletter en 2 cijfers met een totale lengte van 8 tekens       
      * Kies posities voor vereisten
       PERFORM FILLREQUIREDVALUES
    
       
      
      * Vul alle posities op en voeg ze toe aan het wachtwoord
      * Locaties van verplichte tekens krijgen een random passende waarde toegekend
      * Verdere locaties krijgen een willekeurig teken toegewezen
      
       PERFORM WITH TEST BEFORE VARYING COUNTER
       FROM 1 BY 1 UNTIL COUNTER EQUAL 8
         EVALUATE COUNTER
           WHEN CAPITALLOC
             PERFORM RANDOMCAPITAL
           WHEN NUMBER1LOC
             PERFORM RANDONNUMBER
           WHEN NUMBER2LOC
             PERFORM RANDONNUMBER
           WHEN OTHER
             PERFORM RANDOMSIGN
         END-EVALUATE
         
         MOVE RANDOMSIGNVALUE TO PASSWORDVALUE(COUNTER)
        
       END-PERFORM
       
      * PERFORM FILLSTRING 
      
       EXIT PROGRAM 
      
                     
      * Kies een willekeurig teken
       RANDOMSIGN.
       COMPUTE RANDOMPOINTER = ((FUNCTION RANDOM) * 3) + 1
       
       EVALUATE RANDOMPOINTER
         WHEN 1
           PERFORM RANDONNUMBER
         WHEN 2
           PERFORM RANDOMCAPITAL
         WHEN 3 
           PERFORM RANDOMLOWERCASE
         WHEN OTHER
           DISPLAY "I took a wrong turn"
       END-EVALUATE
       
      * Kies locatie verplichte tekens
       FILLREQUIREDVALUES.
       COMPUTE CAPITALLOC = ((FUNCTION RANDOM) * 8) + 1

       PERFORM TEST AFTER UNTIL NUMBER1LOC NOT EQUAL CAPITALLOC
         COMPUTE NUMBER1LOC = ((FUNCTION RANDOM) * 8) + 1
       END-PERFORM
       
       PERFORM TEST AFTER UNTIL NUMBER2LOC NOT EQUAL CAPITALLOC 
                            AND NUMBER2LOC NOT EQUAL NUMBER1LOC
         COMPUTE NUMBER2LOC = ((FUNCTION RANDOM) * 8) + 1
       END-PERFORM
       
      *Kies willekeurige hoofdletter       
       RANDOMCAPITAL.
       COMPUTE RANDOMPOINTER = ((FUNCTION RANDOM) * 26) + 1
       UNSTRING PASSWORDUPPERCASE 
         INTO RANDOMSIGNVALUE 
         POINTER RANDOMPOINTER
       END-UNSTRING
       
      *Kies willekeurige letter       
       RANDOMLOWERCASE.
       COMPUTE RANDOMPOINTER = ((FUNCTION RANDOM) * 26) + 1
       UNSTRING PASSWORDLOWERCASE 
         INTO RANDOMSIGNVALUE
         POINTER RANDOMPOINTER
       END-UNSTRING       
       
      * Kies willekeurig cijfer 
       RANDONNUMBER.
       COMPUTE RANDOMPOINTER = ((FUNCTION RANDOM) * 10) + 1
       UNSTRING PASSWORDNUMBERS 
         INTO RANDOMSIGNVALUE 
         POINTER RANDOMPOINTER
       END-UNSTRING
       
       FILLSTRING.
       INITIALIZE COUNTER
       PERFORM WITH TEST BEFORE VARYING COUNTER
       FROM 1 BY 1 UNTIL COUNTER EQUAL 8
       STRING PASSWORDVALUE(COUNTER)
       DELIMITED BY SPACES
       INTO PASSWORDSTRING
       POINTER COUNTER
       END-STRING
       END-PERFORM